<div id="admin-links">
	<a href="index.php?s=tournament-management">Tournament Management</a>
	<a href="index.php?s=tournament-management&a=1">New Tournament</a>		
</div>
<div id="content">
<?php
	$action = REPLACE_Injection($_GET["a"]);
	if($action == 1){		
		?>
		<h1>Tournament Creation</h1>
		<form action="index.php?s=tournament-management&a=2" method="post">
		<table border="0" cellspacing="0" cellpadding="0" class="form">
			<tr>
				<td><strong>Tournament Name</strong></td>
				<td><input type="text" maxlength="255" size="50" name="name" /></td>
			</tr>
			<tr>
				<td><strong>Tournament Type</strong></td>
				<td>
					<select name="type">
						<option value="1">Individual Tournament - Random Team</option>
						<option value="2">Couples Tournament - Random Team</option>
						<option value="3">Individual Tournament - Player Fixed Team</option>
						<option value="4">Couples Tournament - Player Fixed Team</option>
						<option value="5">Random Couples Tournament - Random Team</option>
					</select>
				</td>
			</tr>
			<tr>
				<td><strong>Matches to play per Match</strong></td>
				<td>
					<select name="return">
						<option value="0">First Leg Only (1 match)</option>
						<option value="1">First &amp; Second Leg (2 matches)</option>
					</select>
				</td>
			</tr>
			<tr>
				<td><strong>Teams Available</strong></td>
				<td>
					<select name="teams">
						<option value="0">All</option>
						<option value="1">All Without National Teams</option>
						<option value="2">National Teams</option>
						<option value="3">Liga BBVA</option>
						<option value="4">Bundesliga</option>
						<option value="5">Premier League</option>
						<option value="6">Serie A</option>
						<option value="7">Ligue 1</option>
						<option value="8">Other European Teams</option>
						<option value="9">All European Leagues</option>
						<option value="10">Latin American Teams</option>
						<option value="11">5 stars</option>
						<option value="12">4 stars</option>
						<option value="13">3 stars</option>
						<option value="14">2 stars</option>
						<option value="15">1 star</option>						
					</select>
				</td>
			</tr>
			<tr>
				<td><strong>Continent</strong></td>
				<td>
					<select name="continent">
						<option value="0">All</option>
						<option value="1">Europe</option>
						<option value="2">Asia</option>
						<option value="3">Africa</option>
						<option value="4">America</option>
						<option value="5">Oceania</option>
					</select>
				</td>
			</tr>
			<tr>
				<td><strong>Inscription Opening</strong></td>
				<td>
					<select name="inscription-date-day">
						<?php 
							for($i = 1; $i <= 31; $i++){
								echo '<option value="'.$i.'">'.$i.'</option>';
							}
						?>
					</select>
					<select name="inscription-date-month">
						<?php 
							for($i = 1; $i <= 12; $i++){
								echo '<option value="'.$i.'">'.$i.'</option>';
							}
						?>
					</select>
					<select name="inscription-date-year">
						<?php 
							for($i = 2011; $i <= 2015; $i++){
								echo '<option value="'.$i.'">'.$i.'</option>';
							}
						?>
					</select>
				</td>			
			</tr>
			<tr>
				<td><strong>Starting Date</strong></td>
				<td>
					<select name="start-date-day">
						<?php 
							for($i = 1; $i <= 31; $i++){
								echo '<option value="'.$i.'">'.$i.'</option>';
							}
						?>
					</select>
					<select name="start-date-month">
						<?php 
							for($i = 1; $i <= 12; $i++){
								echo '<option value="'.$i.'">'.$i.'</option>';
							}
						?>
					</select>
					<select name="start-date-year">
						<?php 
							for($i = 2011; $i <= 2015; $i++){
								echo '<option value="'.$i.'">'.$i.'</option>';
							}
						?>
					</select>
				</td>			
			</tr>
			<tr><td colspan="2"><input type="submit" value="Create Tournament" class="boton"/></td></tr>
		</table>
		</form>
		<?php 
	}else if($action == 2){
		/* Tournament Insertion */
		if(!$nombre = REPLACE_Injection($_POST["name"]))
			$error .= "Tournament Name is not optional field<br>";		
		if(!$tipo = REPLACE_Injection($_POST["type"]))
			$error .= "Tournament Type is not optional field<br>";		
		if(!$fecha_inscripcion = gmmktime(0,0,0,REPLACE_Injection($_POST["inscription-date-month"]), REPLACE_Injection($_POST["inscription-date-day"]), REPLACE_Injection($_POST["inscription-date-year"])))
			$error .= "Inscription date is invalid<br>";
		if(!$fecha_inicio = gmmktime(0,0,0,REPLACE_Injection($_POST["start-date-month"]), REPLACE_Injection($_POST["start-date-day"]), REPLACE_Injection($_POST["start-date-year"])))
			$error .= "Inscription date is invalid<br>";
		$fecha_fin = 0;
		
		$ida_vuelta = REPLACE_Injection($_POST["return"]);
			
		$equipos = REPLACE_Injection($_POST["teams"]);
		$continente = REPLACE_Injection($_POST["continent"]);
			
		if($fecha_inscripcion >= $fecha_inicio)
			$error .= "The inscription date must be before the tournament starting date<br>";
		
		if(sizeof($error) == 0){
			$values = array(NULL, $nombre, $fecha_inscripcion, $fecha_inicio, $fecha_fin, $tipo, 1, $equipos, $continente, 0, 0, $ida_vuelta);
			$insert = new mysqlInsert("tournament", "", "torneo", $values);
			$insert->execute();
			?>
			<h1>Tournament Creation</h1>
			<div id="ok">The tournament has been created.</div>
			<a href="index.php?s=tournament-management" class="back">Back to Management</a>
			<?php
		}else{
			?>			
			<h1>Tournament Creation</h1>
			<div id="error">You have the following errors: <br><br><?php echo $error;?></div>
			<a href="index.php?s=tournament-management&a=1" class="back">Back to Tournament Creation</a>
			<?php
		}
	}else if($action == 3){
		?>
		<h1>Tournament Edition</h1>
		<?php
			$id = REPLACE_Injection($_GET["id"]); 
			$query = new mysqlQuery("tournament", "", "torneo", "*", "`id`='".$id."'", "", "");
			$query->execute();
			if($query->getCount() == 1){
				$row = $query->next();
				$nombre = $row["nombre"];
				$tipo = $row["tipo"];
				$estado = $row["estado"];
				$diaInscripcion = gmdate("j", $row["fecha_inscripcion"]);
				$mesInscripcion = gmdate("n", $row["fecha_inscripcion"]);
				$anyoInscripcion = gmdate("Y", $row["fecha_inscripcion"]);
				$diaInicio = gmdate("j", $row["fecha_inicio"]);
				$mesInicio = gmdate("n", $row["fecha_inicio"]);
				$anyoInicio = gmdate("Y", $row["fecha_inicio"]);
				$equipos = $row["equipos"];
				$continente = $row["continente"];
				$idaVuelta = $row["ida_vuelta"];
				?>
				<form action="index.php?s=tournament-management&a=4&id=<?php echo $id;?>" method="post">
				<table border="0" cellspacing="0" cellpadding="0" class="form">
					<tr>
						<td><strong>Tournament Name</strong></td>
						<td><input type="text" maxlength="255" size="50" name="name" value="<?php echo $nombre;?>" /></td>
					</tr>
					<tr>
						<td><strong>Tournament Type</strong></td>
						<td>
							<select name="type">
								<?php 
								switch($tipo){
									case 1: 	echo '<option value="1" selected>Individual Tournament - Random Team</option>
															<option value="2">Couples Tournament - Random Team</option>
															<option value="3">Individual Tournament - Player Fixed Team</option>
															<option value="4">Couples Tournament - Player Fixed Team</option>
															<option value="5">Random Couples Tournament - Random Team</option>'; 
													break;
									case 2: 	echo '<option value="1">Individual Tournament - Random Team</option>
															<option value="2" selected>Couples Tournament - Random Team</option>
															<option value="3">Individual Tournament - Player Fixed Team</option>
															<option value="4">Couples Tournament - Player Fixed Team</option>
															<option value="5">Random Couples Tournament - Random Team</option>'; 
									break;
									case 3: 	echo '<option value="1">Individual Tournament - Random Team</option>
															<option value="2">Couples Tournament - Random Team</option>
															<option value="3" selected>Individual Tournament - Player Fixed Team</option>
															<option value="4">Couples Tournament - Player Fixed Team</option>
															<option value="5">Random Couples Tournament - Random Team</option>'; 
									break;
									case 4: 	echo '<option value="1">Individual Tournament - Random Team</option>
															<option value="2">Couples Tournament - Random Team</option>
															<option value="3">Individual Tournament - Player Fixed Team</option>
															<option value="4" selected>Couples Tournament - Player Fixed Team</option>
															<option value="5">Random Couples Tournament - Random Team</option>'; 
									break;
									case 5: 	echo '<option value="1">Individual Tournament - Random Team</option>
															<option value="2">Couples Tournament - Random Team</option>
															<option value="3">Individual Tournament - Player Fixed Team</option>
															<option value="4">Couples Tournament - Player Fixed Team</option>
															<option value="5" selected>Random Couples Tournament - Random Team</option>'; 
									break;
								}
								
								?>
							</select>
						</td>
					</tr>					
					<tr>
						<td><strong>Matches to play per Match</strong></td>
						<td>
							<select name="return">
							<?php 
								switch($idaVuelta){
									case 0: echo '	<option value="0" selected>First Leg Only (1 match)</option>
																<option value="1">First &amp; Second Leg (2 matches)</option>'; 
													break;
									case 1: echo '	<option value="0">First Leg Only (1 match)</option>
																<option value="1" selected>First &amp; Second Leg (2 matches)</option>';
								}
							?>
							</select>
						</td>
					</tr>	
					<tr>
						<td><strong>Teams Available</strong></td>
						<td>
							<select name="teams">
							<?php
								switch($equipos){
									case 0: echo '<option value="0" selected>All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>
															';
															break;
									case 1: echo '<option value="0">All</option>
															<option value="1" selected>All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 2: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2" selected>National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 3: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3" selected>Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 4: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4" selected>Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 5: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5" selected>Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 6: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6" selected>Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 7: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7" selected>Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 8: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8" selected>Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 9: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9" selected>All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 10: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10" selected>Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
									case 11: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11" selected>5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
										case 12: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12" selected>4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
										case 13: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13" selected>3 stars</option>
															<option value="14">2 stars</option>
															<option value="15">1 star</option>';
															break;
										case 14: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14" selected>2 stars</option>
															<option value="15">1 star</option>';
															break;
										case 15: echo '<option value="0">All</option>
															<option value="1">All Without National Teams</option>
															<option value="2">National Teams</option>
															<option value="3">Liga BBVA</option>
															<option value="4">Bundesliga</option>
															<option value="5">Premier League</option>
															<option value="6">Serie A</option>
															<option value="7">Ligue 1</option>
															<option value="8">Other European Teams</option>
															<option value="9">All European Leagues</option>
															<option value="10">Latin American Teams</option>
															<option value="11">5 stars</option>
															<option value="12">4 stars</option>
															<option value="13">3 stars</option>
															<option value="14">2 stars</option>
															<option value="15" selected>1 star</option>';
															break;
								} 
								
							?>
							</select>
						</td>
					</tr>
					<tr>
						<td><strong>Continent</strong></td>
						<td>
							<select name="continent">
								<?php 
									switch($continente){
										case 0: echo '
													<option value="0" selected>All</option>
													<option value="1">Europe</option>
													<option value="2">Asia</option>
													<option value="3">Africa</option>
													<option value="4">America</option>
													<option value="5">Oceania</option>';
													break;
										case 1: echo '
													<option value="0">All</option>
													<option value="1" selected>Europe</option>
													<option value="2">Asia</option>
													<option value="3">Africa</option>
													<option value="4">America</option>
													<option value="5">Oceania</option>';
													break;
										case 2: echo '
													<option value="0">All</option>
													<option value="1">Europe</option>
													<option value="2" selected>Asia</option>
													<option value="3">Africa</option>
													<option value="4">America</option>
													<option value="5">Oceania</option>';
													break;
										case 3: echo '
													<option value="0">All</option>
													<option value="1">Europe</option>
													<option value="2">Asia</option>
													<option value="3" selected>Africa</option>
													<option value="4">America</option>
													<option value="5">Oceania</option>';
													break;
										case 4: echo '
													<option value="0">All</option>
													<option value="1">Europe</option>
													<option value="2">Asia</option>
													<option value="3">Africa</option>
													<option value="4" selected>America</option>
													<option value="5">Oceania</option>';
													break;
										case 5: echo '
													<option value="0">All</option>
													<option value="1">Europe</option>
													<option value="2">Asia</option>
													<option value="3">Africa</option>
													<option value="4">America</option>
													<option value="5" selected>Oceania</option>';
													break;
									}
								?>
							</select>
						</td>
					</tr>
					<tr>
						<td><strong>Inscription Opening</strong></td>
						<td>
							<select name="inscription-date-day">
								<?php 
									for($i = 1; $i <= 31; $i++){
										if($i == $diaInscripcion)
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										else
											echo '<option value="'.$i.'">'.$i.'</option>';
									}
								?>
							</select>
							<select name="inscription-date-month">
								<?php 
									for($i = 1; $i <= 12; $i++){
										if($i == $mesInscripcion)
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										else
											echo '<option value="'.$i.'">'.$i.'</option>';
									}
								?>
							</select>
							<select name="inscription-date-year">
								<?php 
									for($i = 2011; $i <= 2015; $i++){
										if($i == $anyoInscripcion)
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										else
											echo '<option value="'.$i.'">'.$i.'</option>';
									}
								?>
							</select>
						</td>			
					</tr>
					<tr>
						<td><strong>Starting Date</strong></td>
						<td>
							<select name="start-date-day">
								<?php 
									for($i = 1; $i <= 31; $i++){
										if($i == $diaInicio)
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										else
											echo '<option value="'.$i.'">'.$i.'</option>';
									}
								?>
							</select>
							<select name="start-date-month">
								<?php 
									for($i = 1; $i <= 12; $i++){
										if($i == $mesInicio)
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										else
											echo '<option value="'.$i.'">'.$i.'</option>';
									}
								?>
							</select>
							<select name="start-date-year">
								<?php 
									for($i = 2011; $i <= 2015; $i++){
										if($i == $anyoInicio)
											echo '<option value="'.$i.'" selected>'.$i.'</option>';
										else
											echo '<option value="'.$i.'">'.$i.'</option>';
									}
								?>
							</select>
						</td>			
					</tr>
					<tr>
						<td>Status</td>
						<td>
							<select name="status">
								<?php 
									switch($estado){
										case 0: 	echo '<option value="0" selected>Scheduled</option>
																<option value="1">Inscription Open</option>
																<option value="2">Started</option>
																<option value="3">Finished</option>';
														break;
										case 1: 	echo '<option value="0">Scheduled</option>
																<option value="1" selected>Inscription Open</option>
																<option value="2">Started</option>
																<option value="3">Finished</option>';
										break;
										case 2: 	echo '<option value="0">Scheduled</option>
																<option value="1">Inscription Open</option>
																<option value="2" selected>Started</option>
																<option value="3">Finished</option>';
										break;
										case 3: 	echo '<option value="0">Scheduled</option>
																<option value="1">Inscription Open</option>
																<option value="2">Started</option>
																<option value="3" selected>Finished</option>';
										break;
									}
								?>
							</select>
						</td>
					</tr>
					<tr><td colspan="2"><input type="submit" value="Update Tournament" class="boton"/></td></tr>
				</table>
				</form>
				<?php
			}else{
				echo '<div id="error">Tournament does not exist</div>';
			} 
	}else if($action == 4){
		$id = REPLACE_Injection($_GET["id"]);
		if(!$nombre = REPLACE_Injection($_POST["name"]))
			$error .= "Tournament Name is not optional field<br>";		
		if(!$tipo = REPLACE_Injection($_POST["type"]))
			$error .= "Tournament Type is not optional field<br>";		
		if(!$fecha_inscripcion = gmmktime(0,0,0,REPLACE_Injection($_POST["inscription-date-month"]), REPLACE_Injection($_POST["inscription-date-day"]), REPLACE_Injection($_POST["inscription-date-year"])))
			$error .= "Inscription date is invalid<br>";
		if(!$fecha_inicio = gmmktime(0,0,0,REPLACE_Injection($_POST["start-date-month"]), REPLACE_Injection($_POST["start-date-day"]), REPLACE_Injection($_POST["start-date-year"])))
			$error .= "Inscription date is invalid<br>";
		$fecha_fin = 0;
		if(!$equipos = REPLACE_Injection($_POST["teams"]))
			$error .= "The selected League is not valid<br>";		

		$ida_vuelta = REPLACE_Injection($_POST["return"]);
		
		if($fecha_inscripcion >= $fecha_inicio)
			$error .= "The inscription date must be before the tournament starting date<br>";
		
		$estado = REPLACE_Injection($_POST["status"]);
		if(sizeof($error) == 0){
			/* Tournament Update */
			$values = array("nombre", "tipo", "fecha_inscripcion", "fecha_inicio", "fecha_fin", "estado", "equipos", "continente", "ida_vuelta");
			$data = array($nombre, $tipo, $fecha_inscripcion, $fecha_inicio, $fecha_fin, $estado, $equipos, $continente, $ida_vuelta);
			$update = new mysqlUpdate("tournament", "", "torneo", $values, $data, "`id`='".$id."'");
			$update->execute();
			?>
			<h1>Tournament Edition</h1>
			<div id="ok">The tournament has been modified..</div>
			<a href="index.php?s=tournament-management" class="back">Back to Management</a>
			<?php
		}else{
			?>
			<h1>Tournament Edition</h1>
			<div id="error">You have the following errors: <br><br><?php echo $error;?></div>
			<a href="index.php?s=tournament-management&a=3&id=<?php echo $id;?>" class="back">Back to Tournament Edition</a>
			<?php
		}
	}else{
		?>
		<h1>Tournament Management</h1>
		
		<table border="0" cellspacing="0" cellpadding="0" class="table">
			<tr>
				<td class="title">Tournament Name</td>
				<td class="title">Status</td>
				<td class="title">Inscription</td>
				<td class="title">Starts</td>
				<td class="title">Ends</td>
				<td class="title">Teams</td>
				<td class="title">Continent</td>
				<td class="title" colspan="1">Operations</td>
			</tr>
			<?php 
				$query = new mysqlQuery("tournament", "", "torneo", "", "", "estado", "ASC");
				$query->execute();
				$n = 0;
				while($row = $query->next()){
					switch($row["estado"]){
						case 0: $tipo = "<span style='color:#000; font-weight: bold'>Scheduled</span>"; break;
						case 1: $tipo = "<span style='color:#FFCC33; font-weight: bold'>Inscription Open</span>"; break;
						case 2: $tipo = "<span style='color:#090; font-weight: bold'>Started</span>"; break;
						case 3: $tipo = "<span style='color:#900; font-weight: bold'>Finished</span>"; break;
					}
					echo '<tr>';
					echo '<td class="td'.(($n%2)+1).'"><strong>'.$row["nombre"].'</strong></td>';
					echo '<td class="td'.(($n%2)+1).'">'.$tipo.'</td>';
					echo '<td class="td'.(($n%2)+1).'">'.unixDateTournament($row["fecha_inscripcion"]).'</td>';
					echo '<td class="td'.(($n%2)+1).'">'.unixDateTournament($row["fecha_inicio"]).'</td>';
					echo '<td class="td'.(($n%2)+1).'">'.obtenerEquiposTorneo($row["equipos"]).'</td>';
					echo '<td class="td'.(($n%2)+1).'">'.obtenerContinenteTorneo($row["continente"]).'</td>';
					echo '<td class="td'.(($n%2)+1).'"><a href="index.php?s=tournament-management&a=3&id='.$row["id"].'">Edit</a></td>';
					//echo '<td class="td'.(($n%2)+1).'"><a href="index.php?s=tournament-management&a=5&id='.$row["id"].'">Delete</a></td>';
					echo '</tr>';
					$n++;
				}				
			?>
		</table>
		<?php 
	}
?>
</div>